<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php echo $phpJS; ?>

<div id="center-wrap" class="ui-corner-tl ui-corner-tr">
	<div id="navigation" class="ui-corner-all"><ul><?php echo $navigator;?></ul></div>
	
	<div class="clrboth"></div>
	
<form action="<?php echo site_url('buyer/my_bids/search');?>" name="bids" id="bids" method="get" enctype="multipart/form-data" >
	
	<?php 
		$ci=& get_instance();
		$bidStatus = bidStatusDataConfig();	
		$title = isset($_GET['title'])? $_GET['title'] : 'Title';									
		$MY_ACC = $this->user_entity->init('id', $_SESSION['user']['id']);
	?>
	
	<div class="row">
		<div class="column grid_9">
			<p class="bold"> &raquo; Search Bids:</p>
		</div>
		<div class="clrboth"></div>
		<div class="column grid_9">
			<input type="text" name="title" id="title" value="<?php echo $title;?>" style="width:335px;" />
			<div class="clrboth"></div>	
			<div style="width:0px;height:10px;"></div>
			
			<input type="submit" style="margin-top:20px;" id="button_submit" name="button_submit" value="Search" class="ui-corner-all button-yellow" />
			
			<div class="clrboth"></div>
		</div>
	</div>
	<div class="clrboth"></div>
	
	<div style="width:0px;height:30px;"></div>
	
	<div class="column grid_4">
		<span class="bold" style="float:left;margin-right:15px;">Show</span>
		<?php echo form_dropdown( 'records_per_page',
								$options = showNumberRecordsPerPageDataConfig(),
								$selected = array( isset($_GET['records_per_page'])? $_GET['records_per_page']: defaultNumberRecordsPerPageShowDataConfig() ),
								"id='records_per_page' onchange='javascript:change_num_per_page(this.value);' style='float:left;' " );
		?>
		&nbsp;
		<?php 
			$num_results = $items['total_records'];
			if( $num_results > 1 ){
				echo " of ". $num_results." records.";
			}else if( $num_results == 1 ){
				echo " of ". $num_results." record.";
			}
		?>
	</div>
	
	<div class="column grid_5">
		<div id="pagination">
			<?php 
				echo $items['pagination']['links'];
			?>
		</div>
	</div> 
	
	<div class="clrboth"></div>
	<div id="result_display">
		<table>
			<thead>
				<td width="100px">Show Ref</td>
				<td width="100px">Bid Ref</td>
				<td width="200px">Artist</td>
				<td width="100px">Amount</td>
				<td width="100px">Date Submit</td>
				<td width="100px">Status</td>
				<td width="200px">Actions</td>
			</thead>
			<tbody>
			 
				<?php if(!empty($items['items'])):?>
					<?php foreach($items['items'] as $object):?>
						<?php 
							$SHOW = $ci->show_entity->init('ref_no', $object->show_ref_no) ;
							$BID = $ci->bid_entity->init('id', $object->id);
						?>
						<tr>
							<td><a href="<?php echo site_url("buyer/shows/view")."/".$SHOW->getRefNo(); ?>"><?php echo $SHOW->getRefNo();?></a></td>
							<td><?php echo $BID->getId();?></td>
							<td><?php echo $SHOW->getArtist();?></td>
							<td><?php echo $BID->getOfferPrice();?></td>
							<td><?php echo sbxDateFormat($BID->getDateBid(), 'd/M/Y');?></td>
							<td>
								<?php
									if($SHOW->getStatus() == "opening"){
										echo $bidStatus["bidding"];
									}else if($SHOW->getStatus() == "closed"){
										if($SHOW->getUserBidWon() == $MY_ACC->getId()){
											echo $bidStatus["won"];
										}else{
											echo $bidStatus["lost"];
										}
									}	
									
								?>
							</td>
							<td>
								<?php if($SHOW->getStatus() == "opening"): ?>
									<a class="manage ui-corner-all" href="<?php echo site_url("buyer/shows/edit_bid/?ref_no=".$SHOW->getRefNo()."&scrid=".$SHOW->makescrid());?>">Edit</a>
									&nbsp;&nbsp;&nbsp;
									<a class="manage ui-corner-all" href="javascript:void(0);" onclick="delete_bid('<?php echo $SHOW->getRefNo();?>');" >Withdraw</a>
									&nbsp;&nbsp;&nbsp;
								<?php else: ?>	
									<a class="manage ui-corner-all" href="<?php echo site_url("buyer/shows/edit_bid/?ref_no=".$SHOW->getRefNo()."&scrid=".$SHOW->makescrid());?>">View</a>
								<?php endif; ?>	
							</td>
						</tr>
					<?php endforeach; ?>
				<?php endif; ?>
			</tbody>
		</table>
	</div>
	
	<div class="clrboth"></div>
	
	<div class="column grid_4">
		<span class="bold" style="float:left;margin-right:15px;">Show</span>
		<?php echo form_dropdown( 'records_per_page',
										$options = showNumberRecordsPerPageDataConfig(),
										$selected = array( isset($_GET['records_per_page'])? $_GET['records_per_page']: defaultNumberRecordsPerPageShowDataConfig() ),
										"id='records_per_page' onchange='javascript:change_num_per_page(this.value);' style='float:left;' " );
		?>
		&nbsp;
		<?php 
			$num_results = $items['total_records'];
			if( $num_results > 1 ){
				echo " of ". $num_results." records.";
			}else if( $num_results == 1 ){
				echo " of ". $num_results." record.";
			}
		?>
	</div>
	
	<div class="column grid_5">
		<div id="pagination">
			<?php 
				echo $items['pagination']['links'];
			?>
		</div>
	</div> 
	
	<div class="clrboth"></div>
	<div style="width:0px;height:30px;"></div>
	<div class="clrboth"></div>
</form>	
</div>
<div class="clrboth"></div>

<script type="text/javascript">
	$(function(){
		$('#title').click(function(){
			if($(this).val() == 'Title'){
				$(this).attr('value','');
			}
		});
		$('#title').bind('focusout',function(){
			if($(this).val() == ''){
				$(this).attr('value','Title');
			}
		});
	});
	function change_num_per_page(value){
		__GET.records_per_page = value;
		__GET.per_page = "";
		_makeQueryURL();
	}
	function delete_bid($ref_no){
		$.post(BASE_URI+"buyer/my_bids/delete_bid",{ref_no:$ref_no},function(response){
			window.location.reload();
		});
	}
</script>
